<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/30
 * Time: 11:18
 */

namespace app\console\model;


use think\Model;

class GiftOrderTwo extends Model
{
    protected $insert = ['create_time' => '2011-02-16 11:11:11'];
//    protected $autoWriteTimestamp = 'datetime';

    protected function setCreateTimeAttr()
    {
        return date('Y-m-d H:i:s',time());
    }



    public static function init()
    {
        self::event('before_insert', function ($data) {

            $order = \think\Db::name('order')->where('id',$data->order_id)->find();

            $data->order_number = $order['order_number'];
            $data->member_id = $order['member_id'];
            $data->username = $order['username'];
            $data->gift_title = $order['gift_title'];
            $data->car_number = $order['car_number'];

            $data->order_number_two = $order['order_number'].'-'. (self::where('order_id',$data['order_id'])->count()+1);
            (new \app\index\controller\MemberMessage())->jpushMessage($order['member_id'],'您的好友:'.$data['car_name'].' 手机号:'.$data['tel'].' 要使用礼包','礼包名称:'.$order['gift_title'].' 请确认',6);


//            if($data['type'] == 3){ //简历次数
//
//                (new Member())->where('id',$data['member_id'])->setInc('jianli_num',$data['classorcourse_title']);
//            }
        });
        self::event('before_write', function ($data) {
            $data->single_pic = uploadImg('single_pic');
        });

        self::event('after_insert', function ($data) {

            $insertAll = [
                'member_id' => $data['member_id'],
                'title' => '您的好友:'.$data['car_name'].' 手机号:'.$data['tel'].'要使用你的礼包',
                'content' => '礼包名称:'.$data['gift_title'].' 请确认',
                'create_time' => $data['create_time'],
                'message_id' => 0,
                'type_id' => 6,
                'order_number' => $data['id'],
            ];
            //
            (new \app\index\model\MemberMessage())->insert($insertAll);
        });


    }






}